﻿using System.Collections.Generic;
using System.Linq;
using System.Text;
using Comunication;

namespace ServerDomain.CommandFolder
{
    class ServerServerSendFileContinue : Command
    {
        public byte[] DataByte;

        public ServerServerSendFileContinue(byte[] dataToSend)
        {
            Header = "REQ";
            Cmd = Commands.SERVER_SERVER_SEND_FILE_CONTINUE;
            DataByte = dataToSend;
        }

        public override byte[] ToByteArray()
        {
            UTF8Encoding encoder = new UTF8Encoding();
            byte[] bytesHeader = encoder.GetBytes(Header);
            byte[] bytesCommand = encoder.GetBytes(((int)Cmd).ToString().PadLeft(2, '0'));
            byte[] data = DataByte;
            byte[] dataLength = encoder.GetBytes(data.Length.ToString().PadLeft(5, '0'));
            IEnumerable<byte> bytes = bytesHeader.Concat(bytesCommand).Concat(dataLength).Concat(data);
            return bytes.ToArray();
        }
    }
}
